<?
/** @file
 * @author Andrzej Mararok Wasiak (mararok@gmail.com)
 */

/** Action for controller.
 *  It allows you to perform the associated action in a given context.
 */
class Action {
   private $Name;
   function __construct($name) {
      $this->Name = $name;
   }
   
   /** Execution of the action in the given context
    * @param (object) $context Kontekst
    */   
   function exec($context) {
      $action_name = $this->Name.'Action';
      if ($this->isSupported($context,$this->Name)) {
            return $context->{$action_name}();
      }
      return false;
   }
   
   /** Checking is the action can exec in the given context
    *  @param (object) $context Class instance
    *  @param (string) $actionName Name of action to check
    *  @return (bool) 
    */
   static function isSupported($context,$actionName) {
      $rf = new ReflectionClass(get_class($context));
      return $rf->hasMethod($actioName.'Action');
   }
}

?>